package com.sskj.mine.asset;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.SPUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.asset.data.RechargeTypeBean;
import com.sskj.mine.asset.data.TradeAccountBean;
import com.sskj.mine.asset.data.WithdrawConfigBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.BasePresenter;
import com.sskj.mine.asset.WithdrawActivity;

import java.util.List;

import io.reactivex.Flowable;
import io.reactivex.disposables.Disposable;


/**
 * @author Hey
 * Create at  2019/05/04
 */
class WithdrawPresenter extends BasePresenter<WithdrawActivity> {


//    /**
//     * 提币页面
//     *
//     * @param pid 币种ID
//     * @return
//     */
//    public void getWithdrawConfig(String pid) {
//        httpService.getWithdrawConfig(pid).execute(new JsonCallBack<HttpData<WithdrawConfigBean>>() {
//            @Override
//            public void onSuccess(Response<HttpData<WithdrawConfigBean>> response) {
//                HttpData<WithdrawConfigBean> httpData = response.body();
//                if (httpData.getStatus() == HttpConfig.OK) {
//                    mView.updateUI(httpData.getData());
//                }
//            }
//        });
//    }

    public void sendSms(String account) {
        httpService.sendSms(SPUtil.get(SPConfig.CODE,""),account, "5")
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.sendCheckCodeSuccess();
                        }else {
                            mView.sendCheckCodeFail();

                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        mView.sendCheckCodeFail();
                        super.onError(response);
                    }
                });
    }

    /**
     * 提币
     *
     * @param num     数量
     * @param pid     币id
     * @param tpwd    资金密码
     * @param code    code
     * @param address 地址
     * @return
     */
    public void withdraw(String num, String pid, String tpwd, String code, String address) {
        httpService.withdraw(num, pid, tpwd, code, address).execute(new JsonCallBack<HttpData>(this) {
            @Override
            public void onSuccess(Response<HttpData> response) {
                HttpData httpData = response.body();
                ToastUtil.showShort(httpData.getMsg());
                if (httpData.getStatus() == HttpConfig.OK) {
mView.withdrawSuccess();
                }
            }
        });
    }

    public void getType() {
        httpService.withdrawList()
                .execute(new JsonCallBack<HttpData<TradeAccountBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<TradeAccountBean>> response) {
                        HttpData<TradeAccountBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {


                            Disposable dataDispo = Flowable.fromIterable(httpData.getData().getRes().getAsset())
                                    .filter(item -> item.getIs_act().equals("1"))
                                    .toList()
                                    .subscribe((rechargeTypeBeans, throwable) -> {

                                        mView.updateType(rechargeTypeBeans);
                                    });
                        }
                    }
                });
    }
}
